from PyQt5.Qt import *
from windows.setting_v2 import SettingDockWidget



class Level_2_Widget(QWidget):
    def __init__(self, parent=None, subling:QTreeWidgetItem = None):
        super(Level_2_Widget, self).__init__(parent)


        self.parent = parent
        # from main import MainWin
        # self.parent: MainWin = parent


        self.subling :QTreeWidgetItem= subling
        self.horizontalLayout = QHBoxLayout(self)
        self.horizontalLayout.setSpacing(1)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.space1 = QSpacerItem(100, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(self.space1)
        self.pushButton = QPushButton(self)
        self.parent_model = self.parent.setting_dock.model_manage
        self.parent_model_dict = self.parent.models_dict
        qss = """
        *{
            min-width:2px;
            min-height:2px;
        }
        *:hover{
            background-color:red;
        }
        """
        self.pushButton.setStyleSheet(qss)

        self.pushButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.horizontalLayout.addWidget(self.pushButton)
        self.pushButton.setText("DEL")
        self.pushButton.clicked.connect(self.deleteItem)

    def deleteItem(self):
        if self.subling.checkState(0) == Qt.Checked:
            self.parent_model_dict.pop(self.subling.text(0))
            self.parent.ClearAndRePaintModelManage()


class Level_3_Project_Widget(QWidget):
    def __init__(self, parent=None, text = ""):
        super(Level_3_Project_Widget, self).__init__(parent)

        self.horizontalLayout = QHBoxLayout(self)
        self.horizontalLayout.setSpacing(1)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.lineEdit = QLineEdit(self)
        self.lineEdit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.lineEdit.setText(text)
        self.horizontalLayout.addWidget(self.lineEdit)
        qss = """
        *{
            min-width:5px;
            min-height:5px;
            border:none;
        }
        """
        self.lineEdit.setStyleSheet(qss)

